<?php 
namespace app\home\controller;
use think\Controller;
use think\Db;	
use think\Session;
use think\request;

class Huanx extends Controller{
	
	public function  huanx(){
				$data=$_POST;
				$str=json_encode($data);
				//file_put_contents('./ass01.txt',$str,FILE_APPEND);
				if($data['lcqjgj']=='anR5c2NteHdkeXQ='){
				$ste=Db::name('user_recharge')->where('tradeNo',$data['merBillNo'])->find();
				if($ste['paymentstate']==1)
				{
					return false;die;
				}
				if($ste)
				{
					     //修改充值表
					     Db::table('qfll_user_recharge')->update(['id'=>$ste['id'],'paymentstate'=>1,'platformtradeNo'=>$data['ipsBillNo']]);
					     //资金日志表
					     $zprice=Db::name('cashlog')->where('uid',$ste['uid'])->order('id', 'desc')->limit(0,1)->find();
						 $balance=$zprice['balance']+$ste['amount'];
						 $list=['uid'=>$ste['uid'],'type'=>1,'price'=>$ste['amount'],'balance'=>$balance];
						 Db::table('qfll_cashlog')->insert($list);
						  //存入用户余额
			             Db::table('qfll_users')->where('id', $ste['uid'])->setInc('balance', $ste['amount']);
						 
				     }
					}
				  }
					
	//瑞捷支付异步			  
	public function ruijiepay(){
		            $data=$_GET;
								//file_put_contents('./ass01.txt',$data,FILE_APPEND);
								//file_put_contents('./ass01.txt','ssjdhghddda',FILE_APPEND);
		            $sign=MD5("orderid=".$data['orderid']."&opstate=".$data['opstate']."&ovalue=".$data['ovalue']."1ed2d06b94c343dc9d1baee5b421dcdf");
		             //签名是否成功
		            if($data['sign']==$sign){
									 // file_put_contents('./ass02.txt','签名是否成功',FILE_APPEND);
			             //支付是否成功
			            if($data['opstate']=='0'){
										//file_put_contents('./ass03.txt','支付是否成功',FILE_APPEND);
			            		  //相等
			            		   $ste=Db::name('user_recharge')->where('tradeNo',$data['orderid'])->find();
			            		   //是否写入表
			           if($ste['paymentstate']==1){
											return false;
											die;
										}
									if($ste){
											//修改充值表
										    Db::table('qfll_user_recharge')->update(['id'=>$ste['id'],'paymentstate'=>1,'platformtradeNo'=>$data['sysorderid']]);
											//资金日志表
											$zprice=Db::name('cashlog')->where('uid',$ste['uid'])->order('id', 'desc')->limit(0,1)->find();
											$balance=$zprice['balance']+$ste['amount'];
											$list=['uid'=>$ste['uid'],'type'=>1,'price'=>$ste['amount'],'balance'=>$balance];
											Db::table('qfll_cashlog')->insert($list);
											//存入用户余额
										    Db::table('qfll_users')->where('id', $ste['uid'])->setInc('balance', $ste['amount']);
										  //  header("Location:http://pay.aotuxinxi.cn/Pay/GateWay?ok");die;
										   }
									
				            		
				            	      }
			            	
			             }
			             
			             
		            }
					
	
					
					
				}
?>